package middleware

import (
	"context"
	"mlss-cc-a/logger"
	"net/http"
)

func NewLocateMiddleWare(handler http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		acceptLang := r.Header.Get("Accept-Language")
		logger.Logger().Debugf("acceptLanguate: %v", acceptLang)
		ctx := context.WithValue(r.Context(), "lang", acceptLang)
		//继续下一个拦截器
		handler.ServeHTTP(w, r.WithContext(ctx))
	})
}

func NewLoginMiddleWare(handler http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

		handler.ServeHTTP(w, r.WithContext(context.Background()))
	})
}
